package com.ynding.springboot.model.domain;

import lombok.AccessLevel;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * <p> 双检锁单例模式 </p>
 *
 * @author ynding
 * @version 2022/6/17
 **/
@Data
@NoArgsConstructor(access = AccessLevel.PRIVATE, force = true)
public class Singleton {
    private Long id;

    /**
     * 实列
     */
    private volatile static Singleton instance = null;

    /**
     * 双检锁单例模式
     *
     * @return
     */
    public static Singleton getInstance() {
        if (instance == null) {
            synchronized (Singleton.class) {
                if (instance == null) {
                    instance = new Singleton();
                }
            }
        }
        return instance;
    }
}
